package cn.itcast.web.task;

import cn.itcast.domain.cargo.Contract;
import cn.itcast.domain.cargo.ContractExample;
import cn.itcast.domain.system.User;
import cn.itcast.service.cargo.ContractService;
import cn.itcast.service.system.UserService;
import cn.itcast.web.utils.SpringContextJobUtil;
import com.alibaba.dubbo.config.annotation.Reference;

import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//任务类：等会我的任务目标就是每秒钟输出一次当前系统时间
public class MyTask {
    /**
     * 定时执行的任务方法，5秒执行一次当前方法
     */
    @Reference
    private ContractService contractService;
    @Autowired
    private HttpSession session;
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private UserService userService;

    public void execute() {
        List<Contract> threeDay=contractService.findThreeDay();
        if (threeDay!=null){
            for (Contract contract : threeDay) {
                User user = userService.findById(contract.getCreateBy());
                rabbitTemplate.convertAndSend("email-exchange","msg.send",user);
                System.out.println("定时任务mailReminder在"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"执行成功");
            }
        }

    }




}
